Work around bug in Python's inspect module -- catch an IndexError exception
authorEwan Mellor <ewan@xensource.com>
Sat, 17 Mar 2007 16:56:39 +0000 (16:56 +0000)
committerEwan Mellor <ewan@xensource.com>
Sat, 17 Mar 2007 16:56:39 +0000 (16:56 +0000)
if the source-code lookup fails.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendLogging.py

index 6d6140188d26477419dba3e8af7569d78b2ec498..3d6b678f1d09c31e4fd06bd6f848e7568b24c1a3 100644 (file)
@@ -59,6 +59,18 @@ if 'TRACE' not in logging.__dict__:
                     return filename, frame[2]
     logging.Logger.findCaller = findCaller
 
+    # Work around a bug in Python's inspect module: findsource is supposed to
+    # raise IOError if it fails, with other functions in that module coping
+    # with that, but some people are seeing IndexError raised from there.
+    if hasattr(inspect, 'findsource'):
+        real_findsource = getattr(inspect, 'findsource')
+        def findsource(*args, **kwargs):
+            try:
+                return real_findsource(*args, **kwargs)
+            except IndexError, exn:
+                raise IOError(exn)
+        inspect.findsource = findsource
+
 
 log = logging.getLogger("xend")